const mysql = require('mysql');
const { dbConfig } = require('../config.js')

const mysqlQuery = (sql = '', sqlParams = []) => {
    return new Promise((resolve, reject) => {
        let connection = mysql.createConnection({
            host: dbConfig.host,
            port: dbConfig.port,
            user: dbConfig.user,
            password: dbConfig.password,
            database: dbConfig.database
        });
        connection.connect();
        connection.query(sql, sqlParams, function (err, result) {
            if (err) {
                reject(err.message);
            }else{
                resolve(result);
            }
        });
        connection.end();
    })
}
module.exports = {
    mysqlQuery
}